home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 946 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: lrz-muenchen.de!sun2!ua302aa
  2. From: ua302aa@sun2.lrz-muenchen.de (Kurt Watzka)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: To malloc (new) or not to malloc? When is the question.
  5. Date: 10 Jan 1996 12:08:25 GMT
  6. Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
  7. Distribution: world
  8. Message-ID: <4d0a7p$aco@sparcserver.lrz-muenchen.de>
  9. References: <4ctvk3$ort@maverick.tad.eds.com> <pwolf-0901960912510001@pwolf-mac.qualcomm.com>
  10. NNTP-Posting-Host: sun2.lrz-muenchen.de
  11.  
  12. pwolf@qualcomm.com (Paul I. Wolf ) writes:
  13.  
  14. >In article <4ctvk3$ort@maverick.tad.eds.com>, fignet05.darrins@eds.com
  15. >(Darrin Smith) wrote:
  16. >[snip]
  17. >> Why is it that you can do something like the following: 
  18. >>         char *x; 
  19. >>         x="Some really long string with no particular meaning";
  20. >First example is incorrect. You may be thinking of declaring with initializing:
  21. >   char* x = "Some really long string with no particular meaning";
  22.  
  23. There is nothing "incorrect" about the code posted by Mr. Smith, afaik.
  24. You may assign a pointer to char to a variable of that type without
  25. any special measures, and there is no need to do that in the initialization
  26. of that variable.
  27.  
  28. >Same thing works for second example if you initialize with constants:
  29. >   struct st1{char one[10];
  30. >              char two[20];
  31. >              char three[10];
  32. >              }* sptr= {0};
  33.  
  34. >The point is that memory allocatiion during initialization is required if
  35. >you want the pointer to "automatically" point to memory which can be used.
  36.  
  37. This is _not_ the point in the first example. A pointer to char was
  38. declared. So, space for that pointer has been reserved. The pointer
  39. does not point to a specific memorz location. The assignment changes
  40. the value of the variable "x". No problem there.
  41.  
  42. >In your first example, the "x=" is NOT valid syntax for a sequence of
  43. >characters.
  44.  
  45. It is a valid assignment of a pointer to char.
  46.  
  47. Kurt
  48. --
  49. | Kurt Watzka                             Phone : +49-89-2180-6254
  50. | watzka@stat.uni-muenchen.de
  51. | ua302aa@sunmail.lrz-muenchen.de
  52.